// import './public-path'
import Vue from 'vue'
import ElementUI from 'element-ui'
import './styles/element-variables.scss'
import '@/styles/index.scss' // global css
import App from './App.vue'
import store from './store'
Vue.config.productionTip = false
Vue.use(ElementUI, {
  size: 'small'
})

// window.microApp.addDataListener((data) => {
//   console.log('顶层监听函数 addDataListener', data)
// })

import router from '@/router'
import Components from './components'
import Directives from './directive'
import Mixin from './mixins'
Vue.mixin(Mixin)
Vue.use(Directives)
Vue.use(Components)
// import './permission' // permission control
// 添加全局filter
import filters from './filters'

Object.keys(filters).map((v) => {
  Vue.filter(v, filters[v])
})
let app = null

// -------------------分割线-默认模式------------------ //
// app = new Vue({
//   router,
//   render: h => h(App),
// }).$mount('#app')

// // 监听卸载
// window.unmount = () => {
//   app.$destroy()
//   app.$el.innerHTML = ''
//   app = null
//   console.log('微应用vue2卸载了 -- 默认模式')
// }

// -------------------分割线-umd模式------------------ //
// 👇 将渲染操作放入 mount 函数，子应用初始化时会自动执行
window.mount = () => {
  console.log('window.mount --1')
  app = new Vue({
    router,
    store,
    render: h => h(App)
  }).$mount('#crm-app')
  console.log('微应用crm渲染了 -- UMD模式')
  if (window.microApp) {
    const data = window.microApp.getData()
    console.log('store:', store)
    store.dispatch('user/setUserInfo', data)
    console.log('微应用crm渲染了-data:', data)
  }
}

// 👇 将卸载操作放入 unmount 函数
window.unmount = () => {
  app.$destroy()
  app.$el.innerHTML = ''
  app = null
  console.log('微应用crm卸载了 -- UMD模式')
}

// 如果不在微前端环境，则直接执行mount渲染
if (!window.__MICRO_APP_ENVIRONMENT__ && process.env.NODE_ENV !== 'production') {
  window.mount()
}
console.log('window.__MICRO_APP_ENVIRONMENT__:', window.__MICRO_APP_ENVIRONMENT__)

// -------------------分割线------------------ //
